package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketIssue;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.yangzihui.CouponData;
import com.cskaoyan.service.AdService;
import com.cskaoyan.service.IssueService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @auther: wubang
 * @description:
 * @date: 2022-06-27 10:43
 */

@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;


    @RequiresPermissions(value = {"*","admin:issue:list"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, String question) {
        CommonData<MarketIssue> issues = issueService.selectIssueList(baseParam,question);
        return BaseRespVo.ok(issues);
    }

    @RequiresPermissions(value = {"*","admin:issue:create"},logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map map) {
        String question= (String) map.get("question");
        String answer= (String) map.get("answer");
        MarketIssue issue = issueService.insertIssue(question,answer);
        return BaseRespVo.ok(issue);
    }
    @RequiresPermissions(value = {"*","admin:issue:delete"},logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketIssue marketIssue) {
        issueService.deleteIssue(marketIssue);
        return BaseRespVo.ok();
    }

    @RequiresPermissions(value = {"*","admin:issue:update"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketIssue marketIssue) {
        issueService.updateIssue(marketIssue);
        return BaseRespVo.ok(marketIssue);
    }
}
